import pymysql


def saveinMySQL(data):
    try:
        # 连接数据库
        conn = pymysql.connect(host='127.0.0.1', user='root', password='123456', port=3306, db='python', charset='utf8')
        cur = conn.cursor()
        # 插入数据
        sql = 'insert into last (gdm,type,gqs,pls,bfl,scs) values ("%s","%s",%d,%d,%d,%d);' % (
            data['gdm'], data['type'], data['gqs'], data['pls'], data['bfl'], data['scs'])
        cur.execute(sql)
        conn.commit()
    except:
        # 失败回滚
        conn.rollback()
    finally:
        # 关闭游标、连接
        cur.close()
        conn.close()
